from flask import Flask,request,json,jsonify
from flask_apscheduler import APScheduler
from apscheduler.schedulers.background import BackgroundScheduler
import time
import datetime
from flask_cors import CORS

class Config:
    JOBS = [        
        {
            "id":"999",
            "func":"run:job_999",
            "trigger":"interval",
            "seconds":30
        }
    ]
    # 一定要开启API功能，这样才可以用api的方式去查看和修改定时任务
    SCHEDULER_TIMEZONE = 'Asia/Shanghai'
    SCHEDULER_API_ENABLED = True

def job_999():
    print("定时任务测试！")


app = Flask(__name__)
# 启动定时任务
scheduler = APScheduler(BackgroundScheduler(timezone="Asia/Shanghai"))
app.config.from_object(Config)
scheduler.init_app(app)
scheduler.start()
# 启动定时任务 end




CORS(app,resources={r"/*": {"origins": "*"}}) # 允许所有域名跨域 

# 路由
@app.route('/')
def index():
    return 'Index Page'


if __name__ == '__main__':
    # scheduler = APScheduler()
    # scheduler.init_app(app)
    # scheduler.start()
    app.run(host='0.0.0.0') #监听公网，使外网可以访问本地测试应用服务器，线上不能用这个

